package cn.com.css.taxInspection.attention.service.impl;

import cn.com.css.taxInspection.attention.entity.AttentionCase;
import cn.com.css.taxInspection.attention.entity.ZbxaIndustryEntity;
import cn.com.css.taxInspection.attention.mapper.ZbxaIndustryMapper;
import cn.com.css.taxInspection.attention.service.ZbxaIndustryService;
import cn.com.css.taxInspection.common.exception.BusinessException;
import cn.com.css.taxInspection.common.exception.code.BaseResponseCode;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;


@Service("zbxaIndustryService")
@Slf4j
public class ZbxaIndustryServiceImpl extends ServiceImpl<ZbxaIndustryMapper, ZbxaIndustryEntity> implements ZbxaIndustryService {
    @Resource
    private ZbxaIndustryMapper zbxaIndustryMapper;
    @SuppressWarnings("unchecked")
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void deletedCase(String id) {
        zbxaIndustryMapper.deleteById(id);
    }
    @Override
    public ZbxaIndustryEntity detailInfo(String id) {
        ZbxaIndustryEntity zbxaIndustryEntity = zbxaIndustryMapper.selectById(id);
        if (zbxaIndustryEntity == null) {
            log.error("传入 的 id:{}不合法", id);
            throw new BusinessException(BaseResponseCode.DATA_ERROR);
        }
        return zbxaIndustryEntity;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void addCase(ZbxaIndustryEntity vo) {
        vo.setCreateTime(new Date());
        vo.setUpdateTime(null);
        zbxaIndustryMapper.insert(vo);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void updateCase(ZbxaIndustryEntity vo) {
        ZbxaIndustryEntity zbxaIndustryEntity = zbxaIndustryMapper.selectById(vo.getId());
        if (null == zbxaIndustryEntity) {
            log.error("传入 的 id:{}不合法", vo.getId());
            throw new BusinessException(BaseResponseCode.DATA_ERROR);
        }
        vo.setUpdateTime(new Date());
        zbxaIndustryMapper.updateById(vo);
    }
}